package com.itcast.gateway.handler;

import org.springframework.http.MediaType;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import springfox.documentation.swagger.web.SecurityConfigurationBuilder;

/**
 * @author zheng.zhang
 * Description SwaggerSecurityHandler
 * 在WebFlux的函数式开发模式中，HandlerFunction相当于Controller中的具体处理方法，
 * 输入为请求，输出为装在Mono中的响应
 * @date 2020/9/11 10:49
 * Version 1.0
 */
@Component
public class SwaggerSecurityHandler implements HandlerFunction<ServerResponse> {

    @NonNull
    @Override
    public Mono<ServerResponse> handle(@NonNull ServerRequest request) {
        return ServerResponse.ok()
                .contentType(MediaType.APPLICATION_JSON)
                .body(BodyInserters.fromValue(SecurityConfigurationBuilder.builder().build()));
    }
}
